package com.bestcem.xm.user.dao.impl;

import com.bestcem.xm.user.dao.SsoDao;
import com.bestcem.xm.user.dao.mapper.SsoMapper;
import com.bestcem.xm.user.entity.mysql.Sso;
import com.bestcem.xm.user.entity.pojo.SsoDO;
import com.bestcem.xm.user.util.business.DataBaseUtil;
import com.bestcem.xm.user.util.convert.SsoConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * SSO单点登录Dao
 *
 * @author wangyunyun <yunyun.wang@idiaoyan.com>
 * @version v1.0
 * @date 2022/3/29 10:30
 */
@Repository
public class SsoDaoImpl implements SsoDao {

    @Resource
    private SsoConvert ssoConvert;

    @Resource
    private SsoMapper ssoMapper;

    @Override
    public List<SsoDO> selectBySelective(SsoDO ssoDO) {
        return ssoConvert.mysqls2Dos(ssoMapper.selectBySelective(ssoConvert.do2Mysql(ssoDO)));
    }

    @Override
    public String insertSelective(SsoDO ssoDO) {
        // 设置参数
        Sso entity = ssoConvert.do2Mysql(ssoDO);
        entity.setSsoId(DataBaseUtil.generateId());
        DataBaseUtil.setCreateAndUpdateTime(entity);
        // 更新并返回
        ssoMapper.insertSelective(entity);
        return entity.getSsoId();
    }
}
